package JsonInterface.test;


import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class T6 {
    public static void main(String[] args) {
        String s = "{code=200,msg='hhh'}";
        // 按逗号分割 key-value 对
        /*String[] pairs = s.split(",");

        Map<String, String> map = new HashMap<>();

        // 遍历每个键值对
        for (String pair : pairs) {
            String[] keyValue = pair.split("=");
            String key = keyValue[0].trim();
            String value = keyValue[1].trim().replace("'", ""); // 去掉引号
            map.put(key, value);
        }*/
        // 去除大括号
        s = StringUtils.removeStart(s, "{");
        s = StringUtils.removeEnd(s, "}");

        String[] pairs = StringUtils.split(s, ',');

        Map<String, String> map = new HashMap<>();

        for (String pair : pairs) {
            String[] keyValue = StringUtils.split(pair, '=');
            String key = keyValue[0].trim();
            String value = keyValue[1].trim().replace("'", "");
            map.put(key, value);
        }
        // 打印 map 结果
        System.out.println(map);
        System.out.println(map.get("msg"));
    }
}
